#ifndef COMMON_H
#define COMMON_H
#include <QString>
#include <QColor>
#include <QRectF>
#include <QImage>

// 定义一个宏，将 QRect 转换为格式化的 QString
#define RECT_TO_STRING(rect) QString("Rect: %1x%2") \
    .arg((rect).width()).arg((rect).height())

#define MIN(a,b) ((a) < (b) ? (a) : (b))

#define TIMEMS          qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
#define TIME            qPrintable(QTime::currentTime().toString("HH:mm:ss"))
#define QDATE           qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))
#define QTIME           qPrintable(QTime::currentTime().toString("HH-mm-ss"))
#define DATETIME        qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
#define STRDATETIME     qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
#define STRDATETIMEMS   qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))

//定义换行符
#ifdef Q_OS_WIN
#define NEWLINE "\r\n"
#else
#define NEWLINE "\n"
#endif

//定义无边框标题栏高度+对话框最小宽高
#ifdef __arm__
#define TitleMinSize 40
#define DialogMinWidth 350
#define DialogMinHeight 180
#else
#define TitleMinSize 30
#define DialogMinWidth 280
#define DialogMinHeight 150
#endif

#define GuideLineNum 1000
#define BLOCKINTERVAL 2.0
#define MODELGROUPINTERVAL_H 20
#define MODELGROUPINTERVAL_V 20
#define SOFTPACKCOUNTMAX 60
#define SQUREPACKCOUNTMAX 18
#define RBDUAN 40
#define FKDUAN 40
#define MAINLEFT 0.0
#define MAINRIGHT 240.0
#define MAINTOP 20.0
#define MAINBOTTOM 20.0

struct BlockInfo {
    QString type;       //型号
    QString author;     //厂家
    QString jgtype;     //结构类型
    QString txtype;     //体系类型
    double kWh;         //额定容量
    double voltage;     //额定电压
    double outStopVol;  //放电截至电压
    double inStopVol;   //充电截至电压
    QString outContinue; //持续放电倍率
    QString out10;       //10秒峰值放电倍率
    QString inContinue;  //持续充电倍率
    QString inTemp;      //充电温度
    QString outTemp;     //放电温度
    int weight;         //重量
    double length;      //长
    double width;       //宽
    double height;      //高
    int recircle;       //循环
};

struct ResultInfo {
    QString standerdVol;    //标称电压155.4V
    QString voltageRange;   //电压范围 126-178V
    QString c_b_way;        //串并方案 1P42S
    QString sumkWh;         //总能量   3.5kWh
    QString sumWeight;      //总重量   22kg
    QString continueOuterKW;    //持续放电功率 40kw
    QString outer_10_kw;    //10秒峰值放电功率 10kw
    QString continueInterKW;    //持续充电功率 10kw
    QString pack_l_w_h;     //电池尺寸  243*155*333mm
    QString result;         //结果
    QImage image;           //布置图
};

enum LayoutDirectionHV {
    Left_Top = 0,
    Left_Bottom,
    Right_Top,
    Right_Bottom,
};

enum ResizeDirection {
    None,
    Inner,
    Left,
    Right,
    Top,
    Bottom,
    TopLeft,
    TopRight,
    BottomLeft,
    BottomRight
};

enum rectType{
    Main = 0,
    Module,
    Block,
    Outer
};

struct cutomitem {
    QString name;       // 名称
    QColor color;      // 颜色
    int type;           // 类型
    QRectF rect;        // 矩形参数
};

extern bool g_is_tip_line;
extern bool g_allow_swap_wh;
extern QList<QString> g_item_names;
extern QList<QString> g_item_group_names;
extern QMap<QString,BlockInfo> g_block_map;
extern BlockInfo g_blockInfo;
extern ResultInfo g_resultInfo;
extern double g_duan_value_H;
extern double g_duan_value_V;
#endif // COMMON_H
